package git.soulbgm.mapreduce.partitionerAndComparable;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

/**
 * @author SoulBGM
 * @date 2021/11/21 23:34
 */
public class ProvincePartitioner extends Partitioner<FlowBean, Text> {

    @Override
    public int getPartition(FlowBean flowBean, Text text, int numPartitions) {
        String phone = text.toString();
        String prePhone = null;
        // 136 137 138 139 其他
        if (phone.length() > 2) {
            prePhone = phone.substring(0, 3);
        } else {
            prePhone = phone;
        }
        switch (prePhone) {
            case "136":
                return 0;
            case "137":
                return 1;
            case "138":
                return 2;
            case "139":
                return 3;
            default:
                return 4;
        }
    }

}
